//JavaScript Framework 2.0 Code
try {
	Type.registerNamespace('com.yonyou.ncmm_pac_pda.LoginSettingPage2Controller');
	com.yonyou.ncmm_pac_pda.LoginSettingPage2Controller = function() {
		com.yonyou.ncmm_pac_pda.LoginSettingPage2Controller.initializeBase(this);
		this.initialize();
	}

	function com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$initialize() {
		var host = $cache.read("host") ? $cache.read("host") : "";
		var port = $cache.read("port") ? $cache.read("port") : "";
		var groupcode = $cache.read("groupcode") ? $cache.read("groupcode") : "";

		var settinginfo = {
			"host": host,
			"port": port,
			"groupcode": groupcode
		};

		$ctx.push(settinginfo);
	}

	function com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$evaljs(js) {
		eval(js)
	}

	function com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$btnback_onclick(sender, args) {
		$view.close();
	}

	function btntestconn_onclick2(sender, args) {
		var host = $id("txthost").get("value");
		var port = $id("txtport").get("value");

		if(!host || !port) {
			$toast("请先设置服务器信息");
			return;
		}

		//var serverIP = host + ":" + port;
		//$cache.write("ServerIP", serverIP);

		var state = $app.getNetworkState() || {};
		if(state.available != 'true') {
			$js.toast("网络连接错误！");
			return;
		}
		$js.showLoadingBar({
			msg: '正在检查服务地址是否可用...'
		});
		$app.checkNetWorkReachable(host, port, function(param, args) {
			$js.hideLoadingBar();
			if(args.is_reachable == 'true') {
				$js.toast("服务器地址连接正常！");
				//测试连接通过后将服务器ip写进缓存
		        var serverIP = host + ":" + port;
		        $cache.write("ServerIP", serverIP);
		        $cache.write("host", host);
		        $cache.write("port", port);
			} else {

				$js.toast("服务器地址无法连通！");

			}

		});

		//		NCMMDBUtil.testNCConnection(function(data) {		
		//			if(data == true || data == "true") {
		//				$toast("连接测试通过");
		//			} else {
		//				$toast("连接测试未通过");
		//			}
		//
		//		});
	}

	function com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$wpanelsetting_onload(sender, args) {

	}

	function onSaveBtnClick(sender, args) {
		var host = $id("txthost").get("value");
		var port = $id("txtport").get("value");
		//点击确认后将服务器ip写进缓存
		var serverIP = host + ":" + port;
		$cache.write("ServerIP", serverIP);
		$cache.write("host", host);
		$cache.write("port", port);

		$view.close();

	}
	com.yonyou.ncmm_pac_pda.LoginSettingPage2Controller.prototype = {
		wpanelsetting_onload: com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$wpanelsetting_onload,
		btnback_onclick: com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$btnback_onclick,
		initialize: com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$initialize,
		evaljs: com$yonyou$ncmm_pac_pda$LoginSettingPage2Controller$evaljs
	};
	com.yonyou.ncmm_pac_pda.LoginSettingPage2Controller.registerClass('com.yonyou.ncmm_pac_pda.LoginSettingPage2Controller', UMP.UI.Mvc.Controller);
} catch(e) {
	$e(e);
}
// 打开参照页面
function openRefPage(refinfo, ctxkey) {
	var username = $cache.read("username");
	var password = $cache.read("password");
	if(!username || !password) {
		$toast("请先登录");
		return;
	}
	$view.open({
		viewid: "com.yonyou.ncmm_pac_pda.RefPage", //目标页面
		isKeep: "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
		data: refinfo,
		callback: function() {
			var refdata = $param.getJSONObject("data");
			$ctx.put(ctxkey, refdata.billinfo);
			$ctx.dataBind();
		}
	});
}

function testCallBack() {
	$js.hideLoadingBar();
	var result = $ctx.param("result");
	if(!result || result == "") {
		$toast("测试未通过");
		return;
	}

	$toast("测试通过");
}